package com.eastfair.venueservice.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.ExhibitionSettlement;
import com.eastfair.venueservice.service.ExhibitionSettlementService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.ExhibitionSettlementVO;
import com.eastfair.venueservice.vo.ExhibitionSpaceDrawingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 结算记录
 * </p>
 *
 * @author linan
 * @date 2023-01-10
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionSettlement")
@Api(value = "ExhibitionSettlement", tags = "结算记录")
@PreAuth(replace = "venueservice:exhibitionSettlement:")
public class ExhibitionSettlementController extends SuperController<ExhibitionSettlementService, Long, ExhibitionSettlement, ExhibitionSettlementPageQuery, ExhibitionSettlementSaveDTO, ExhibitionSettlementUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<ExhibitionSettlement> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ExhibitionSettlement> exhibitionSettlementList = list
                .stream()
                .map((map) -> ExhibitionSettlement.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(exhibitionSettlementList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionSettlementPageQuery> params) {
        ExhibitionSettlementPageQuery pageQuery = params.getModel();
    }

    /**
     * 综合-查询结算记录.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("综合-查询结算记录.")
    @PostMapping("/queryExhibitionSettlement")
    public R<List<ExhibitionSettlementVO>> queryExhibitionSettlement(@RequestBody ExhibitionSettlementDTO query) {
        log.info("queryExhibitionSettlement - 综合-查询结算记录., query={}", query);
        return R.success(baseService.queryExhibitionSettlement(query));
    }

    /**
     * 查询场馆待结算的结算单
     *
     * @param query the query
     * @return the r
     */
    @PostMapping("/query/wait/venue/settlement")
    public R<ExhibitionSettlementVO> queryWaitVenueExhibitionSettlement(@RequestBody ExhibitionSettlementDTO query){
        log.info("queryWaitVenueExhibitionSettlement - 查询场馆待结算的结算单, query={}", query);
        return R.successDef(baseService.queryWaitVenueExhibitionSettlement(query));
    }

    /**
     * 查询主场待结算的结算单
     *
     * @param query the query
     * @return the r
     */
    @PostMapping("/query/wait/home/settlement")
    public R<ExhibitionSettlementVO> queryWaitHomeExhibitionSettlement(@RequestBody ExhibitionSettlementDTO query){
        log.info("queryWaitHomeExhibitionSettlement - 查询主场待结算的结算单, query={}", query);
        return R.successDef(baseService.queryWaitHomeExhibitionSettlement(query));
    }

    /**
     * 综合-查询搭建商结算记录.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("综合-查询搭建商结算记录.")
    @PostMapping("/queryExhibitionSettlementOfBuilder")
    public R<List<ExhibitionSettlementVO>> queryExhibitionSettlementOfBuilder(@RequestBody ExhibitionSettlementDTO query) {
        log.info("queryExhibitionSettlementOfBuilder - 综合-查询搭建商结算记录., query={}", query);
        return R.success(baseService.queryExhibitionSettlementOfBuilder(query));
    }

    /**
     * 综合-通过公司ID查询结算记录.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("综合-通过公司ID查询结算记录.")
    @PostMapping("/queryExhibitionSettlementByCompanyId")
    public R<List<ExhibitionSettlementVO>> queryExhibitionSettlementByCompanyId(@RequestBody ExhibitionSettlementDTO query) {
        log.info("queryExhibitionSettlementByCompanyId - 综合-通过公司ID查询结算记录., query={}", query);
        return R.success(baseService.queryExhibitionSettlementByCompanyId(query));
    }

    /**
     * 综合-查询结算明细.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("综合-查询结算明细.")
    @PostMapping("/queryExhibitionSettlementDetail")
    public R<ExhibitionSettlementVO> queryExhibitionSettlementDetail(@RequestBody ExhibitionSettlementDTO query) {
        log.info("queryExhibitionSettlement - 综合-查询结算明细., query={}", query);
        return R.success(baseService.queryExhibitionSettlementDetail(query));
    }

    /**
     * 综合-通过单号查询结算明细.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("综合-通过单号查询结算明细.")
    @PostMapping("/queryDetailBySettlementNo")
    public R<ExhibitionSettlementVO> queryDetailBySettlementNo(@RequestBody ExhibitionSettlementDTO query) {
        log.info("queryDetailBySettlementNo - 综合-通过单号查询结算明细., query={}", query);
        return R.success(baseService.queryDetailBySettlementNo(query));
    }

    /**
     * 综合-查询搭建商结算明细.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("综合-查询搭建商结算明细.")
    @PostMapping("/queryExhibitionSettlementDetailOfBuilder")
    public R<ExhibitionSettlementVO> queryExhibitionSettlementDetailOfBuilder(@RequestBody ExhibitionSettlementDTO query) {
        log.info("queryExhibitionSettlement - 综合-查询搭建商结算明细., query={}", query);
        return R.success(baseService.queryExhibitionSettlementDetailOfBuilder(query));
    }

    /**
     * 取消结算服务项.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("取消结算服务项.")
    @SysLog("取消结算服务项")
    @PostMapping("/cancelSettlementServiceItem")
    public R<Boolean> cancelSettlementServiceItem(@RequestBody ExhibitionSettlementDTO dto) {
        log.info("cancelSettlementServiceItem - 取消结算服务项., dto={}", dto);
        return R.success(baseService.cancelSettlementServiceItem(dto));
    }

    /**
     * 生成结算单.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("生成结算单.")
    @SysLog("生成结算单")
    @PostMapping("/generateSettlement")
    public R<Boolean> generateSettlement(@RequestBody ExhibitionSettlementDTO dto) {
        log.info("generateSettlement - 生成结算单., dto={}", dto);
        return R.success(baseService.generateSettlement(dto));
    }

    /**
     * 主场给搭建商生成结算单.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("主场给搭建商生成结算单.")
    @SysLog("生成结算单")
    @PostMapping("/generateSettlementForBuilder")
    public R<Boolean> generateSettlementForBuilder(@RequestBody ExhibitionSettlementDTO dto) {
        log.info("generateSettlementForBuilder - 主场给搭建商生成结算单., dto={}", dto);
        return R.success(baseService.generateSettlementForBuilder(dto));
    }

    /**
     * 搭建商展位管理申请结算.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("搭建商展位管理申请结算.")
    @SysLog("搭建商展位管理申请结算")
    @PostMapping("/applyForSettlement")
    public R<Boolean> applyForSettlement(@RequestBody ExhibitionSettlementDTO dto) {
        log.info("applyForSettlement - 搭建商展位管理申请结算., dto={}", dto);
        return R.success(baseService.applyForSettlement(dto));
    }

    /**
     * 更新结算单.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("更新结算单.")
    @SysLog("更新结算单")
    @PostMapping("/updateSettlement")
    public R<Boolean> updateSettlement(@RequestBody ExhibitionSettlementDTO dto) {
        log.info("updateSettlement - 更新结算单., dto={}", dto);
        return R.success(baseService.updateSettlement(dto));
    }

    /**
     * 结算认领.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("结算认领.")
    @SysLog("结算认领")
    @PostMapping("/settlementCollect")
    public R<Boolean> settlementCollect(@RequestBody ExhibitionSettlementDTO dto) {
        log.info("settlementCollect - 结算认领., dto={}", dto);
        return R.success(baseService.settlementCollect(dto));
    }

}
